package com.lyd.collections.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.IntFunction;

/**
 * @Author:lyd
 **/
public class StreamDemo7 {
    public static void main(String[] args) {
        ArrayList<String> strList1 = new ArrayList<>();
        Collections.addAll(strList1, "张无忌", "张三丰", "周芷若", "刘备", "孙权", "曹操", "皇太极");

        //toArray()转换成数组不指定类型参数
//        Object[] array = strList1.toArray();
//        System.out.println(Arrays.toString(array));
        /**
         * value指的是数组的大小
         * toArray方法的作用：创建指定大小的数组；把流中的每个数据放到数组中
         */
//        String[] array1 = strList1.toArray(new IntFunction<String[]>() {
//            @Override
//            public String[] apply(int value) {
//                return new String[value];
//            }
//        });
//        System.out.println(Arrays.toString(array1));

        System.out.println(Arrays.toString(strList1.toArray(value -> new String[value])));
    }
}
